/**
 * Created by GG on 2017/3/21.
 */
window.onload=function(){
	$(".nav span").css("border-bottom","0px");
	$(".profile").css("border-bottom","5px solid #e4006e");
	$(".subnav ol.intro").css("display", "block");
	$(".content").css({"display":"block","border-radius": "0 12px 12px 12px"});
	$(".intro1").css("display","block");

};
$(function(){
	$(".close").on("click",function(){

		var opened=window.open('about:blank','_self');
		opened.close();
	})


	$(".subnav ol.intro li").click(function (){
		var index = Number($(this).attr("index"));
		$(".subnav ol.intro li").removeClass('cur');
		$(this).addClass('cur');
		$(".introcont").css("display","none");
		$(".intro"+(index+1)).css("display","block");
	})

	$(".subnav ol.product li").click(function (){
		var index = Number($(this).attr("index"));
		$(".subnav ol.product li").removeClass('cur');
		$(this).addClass('cur');
		$(".productcont").css("display","none");
		$(".product"+(index+1)).css("display","block");
	})
	var mienlazy = {
		pagerows:12,
		requestUrl: "http://op.admin.jufan.tv/api/mienList?callbackname=?",
		detailUrl:"http://op.admin.jufan.tv/api/mienDetail?callbackname=?",
		init: function(objHtml) {
			this.getList(objHtml);
			this.showDetail();
		},
		showData: function (dataList, objHtml){
			var str = "";
			if(this.totalrows > 0){
				$.each(dataList, function (i, item){
					// str += '<p><a href="../html/jobdetail.html?id='+item.id+'">'+item.name+'</a><span>'+item.role+'</span><span>'+item.working_place+'</span><span>'+item.pub_date+'</span></p>'
					if(item.title.length > 20){
						str += '<li index="'+ item.id +'"><img width="396" height="290" src="http://op.admin.jufan.tv/'+ item.pic_url +'" alt=""><p style="line-height:28px">'+ item.title +'</p><p class="mask"></p></li>'
					}else{
						str += '<li index="'+ item.id +'"><img width="396" height="290" src="http://op.admin.jufan.tv/'+ item.pic_url +'" alt=""><p>'+ item.title +'</p><p class="mask"></p></li>'
					}
				})
				$(str).appendTo(objHtml);
			}else{
				$(".loadmore").html('暂无数据')
			}
		},
		showDetail: function (){
			var that = this;
			$(".mien-list").on('click',function (event){
				//var target = event.currentTarget.children;
				console.log(event)
				var target = event.target.offsetParent;
				console.log(event.target.nodeName == "IMG")
				if(event.target.nodeName == "IMG" || event.target.nodeName == "P"){
					var index = $(target).attr("index");
					console.log(target)
					console.log()
					that.getDetail(index);
					$(".mien-list,.loadmore").hide();
					$(".mien-cont").fadeIn();
					$(".mien-cont .back").on('click', function (){
						$(".mien-cont").hide();
						$(".mien-list,.loadmore").fadeIn();
					})
				}
			});
		},
		getDetail: function (index){
			this.detailUrl = this.detailUrl + "&id=" + index;
			$.getJSON(this.detailUrl, function (data){
				$(".details-title").html(data.title);
				$(".details-time").html(data.create_time);
				$(".details-conetxt").html(data.content);
			})
		}
	}
	Object.setPrototypeOf(mienlazy, lazyload);
	mienlazy.init(".mien-list");
})

